package spi;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.Invoker;

/**
 * @author fengbo
 * @version 1.0.0
 * @date 2019/1/13 19:51
 * @since JDK 1.8
 */
public class RobotFilterWrapper implements Robot {

    private Robot robot;

    public RobotFilterWrapper(Robot robot) {
        this.robot = robot;
    }

    @Override
    public void sayHello1(URL url) {
        robot.sayHello1(url);
    }

    @Override
    public void sayHello2(Invoker invoker) {
        // 根据invoker.getUrl()返回值加载Filter，因为URL中包含有Key为test的配置，所以会调用MyFilter
        ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(
                invoker.getUrl(), "myFilter").forEach(Filter::testFilter);
        robot.sayHello2(invoker);
    }
}
